package com.cc.openeye.dynamic.kuikly.recommend.items.square

import com.cc.openeye.dynamic.recommend.entity.dynamicResponse.ItemX
import com.tencent.kuikly.core.base.Color
import com.tencent.kuikly.core.base.ComposeView
import com.tencent.kuikly.core.base.ComposeAttr
import com.tencent.kuikly.core.base.ComposeEvent
import com.tencent.kuikly.core.base.ViewBuilder
import com.tencent.kuikly.core.base.ViewContainer
import com.tencent.kuikly.core.layout.FlexAlign
import com.tencent.kuikly.core.views.Image
import com.tencent.kuikly.core.views.Text
import com.tencent.kuikly.core.views.View

internal class InternalSquareItemContentView :
    ComposeView<InternalSquareItemContentViewAttr, InternalSquareItemContentViewEvent>() {

    override fun createEvent(): InternalSquareItemContentViewEvent {
        return InternalSquareItemContentViewEvent()
    }

    override fun createAttr(): InternalSquareItemContentViewAttr {
        return InternalSquareItemContentViewAttr()
    }

    override fun body(): ViewBuilder {
        val ctx = this
        return {
            attr {
                height(90f)
            }
            Image {
                attr {
                    absolutePositionAllZero()
                    borderRadius(5f)
                    src(ctx.attr.data?.data?.image ?: "")
                    backgroundColor(Color(0xfff5f5f5))
                }
            }

            View {
                attr {
                    alignSelf(FlexAlign.CENTER)
                    marginTop(20f)
                    alignItems(FlexAlign.CENTER)
                }

                Text {
                    attr {
                        text(ctx.attr.data?.data?.title ?: "")
                        color(Color.WHITE)
                        fontSize(16f)
                        fontWeight700()
                    }
                }


                Text {
                    attr {
                        text(ctx.attr.data?.data?.subTitle ?: "")
                        color(Color.WHITE)
                        fontSize(14f)
                        marginTop(10f)
                    }
                }
            }
        }
    }
}


internal class InternalSquareItemContentViewAttr : ComposeAttr() {
    var data: ItemX? = null
}

internal class InternalSquareItemContentViewEvent : ComposeEvent() {

}

internal fun ViewContainer<*, *>.SquareItemContentView(init: InternalSquareItemContentView.() -> Unit) {
    addChild(InternalSquareItemContentView(), init)
}